$begin = 0;
$print = 0;
$status = "<status>\n";
$id = -1;
%statuses = ();

open IDFILE, "<allids" or die "file error";
while(<IDFILE>) {
    chomp;
    $statuses{$_} = 1;
}
close(IDFILE);

while(<>) {
    if(/<\/status>/) {
        $status .= "</status>\n";
        if($print) {
            print $status;
            print "\n";
        }
        $status = "<status>\n";
        $print = 0;
        $id = -1;
        next;
    }
    if(/<status>/) {
        $begin = 1;
    }
    if(not $begin) {
        next;
    }
    if(/<id>([\d]+)<\/id>/) {
        if($id < 0) {
            $id = $1;
            next if exists $statuses{$id};
            $statuses{$id} = 0;
        }
    }
    if(/<text>(.+)<\/text/) {
        if($1 =~ /^(\p{IsASCII}+)$/) {
            if($statuses{$id} == 1) {
                next;
            }
            $print = 1;
            $statuses{$id} = 1;
        }
    }
    $status .= $_;
}

open IDFILE, ">allids" or die "file error";
while( my ($id, $value) = each(%statuses)) {
    if($value == 0) {
        next;
    }
    print IDFILE "$id\n";
}
close(IDFILE);

